<?php
namespace App\Admin\Extensions;

use Encore\Admin\Form\Field;

class WangEditor extends Field
{
    protected $view = 'admin::form.editor';

    protected static $css = [
        '/packages/wangEditor-2.1.22/dist/css/wangEditor.min.css',
    ];

    protected static $js = [
        '/packages/wangEditor-2.1.22/dist/js/wangEditor.min.js',
    ];

    public function render()
    {
        $upUrl = route('admin.wangEditor.upload');
        $token = csrf_token();
        $this->script = <<<EOT

var editor = new wangEditor('{$this->id}');
  // 上传图片（举例）
    editor.config.uploadImgUrl = '{$upUrl}';
    //配置name名称
    editor.config.uploadImgFileName = 'myFileName';
    // 配置自定义参数（举例）
    editor.config.uploadParams = {
        _token: '{$token}'
    };

    // 设置 headers（举例）
    editor.config.uploadHeaders = {
        'Accept' : 'text/x-json'
    };
    editor.create();
EOT;
        return parent::render();

    }
}